#include<iostream>
#include<unistd.h>
using namespace std;

//线程学习
//线程中a是他所看到的共享资源


int a=100;
void * pthread_run1(void * args)
{
   while(true)
   {
    sleep(1);
    cout<<"t1 thread..."<<getpid()<<"&a:"<<&a<<"a:"<<a--<<endl;
   }


}
void * pthread_run2(void * args)
{
   while(true)
   {
    sleep(1);
    cout<<"t2 thread..."<<getpid()<<"&a:"<<&a<<"a:"<<a--<<endl;
   }


}




int main()
{
    pthread_t id1,id2;
    
    pthread_create(&id1,nullptr,pthread_run1,nullptr);
    pthread_create(&id2,nullptr,pthread_run2,nullptr);

    while(true)
    {
        sleep(1);
        cout<<"main thread..."<<getpid()<< "&a:"<<&a<<"a:"<<a<<endl;
    }



    return 0;
}